﻿<Page x:Class="EduAssess.Views.CreateTestPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=CreateTestPageViewModel}"
      mc:Ignorable="d"
      Title="CreateTestPage" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        
        <TextBox Text="{Binding Test.Name}"
                 Grid.Row="0"
                 Margin="200, 20, 200, 20"
                 Background="Transparent"/>
        <ScrollViewer Grid.Row="1">
            <ItemsControl ItemsSource="{Binding Test.Questions}" >
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBox Text="{Binding Name}"
                                     Padding="2"
                                     TextWrapping="Wrap"
                                     TextAlignment="Left"/>
                            <ItemsControl ItemsSource="{Binding Answers}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <RadioButton IsChecked="{Binding IsTrue}"
                                                         GroupName="{Binding RelativeSource={RelativeSource AncestorType=Border}, Path=DataContext.Id}"
                                                         Padding="2"/>
                                            <TextBox Text="{Binding Name}"
                                                     TextAlignment="Left"
                                                     TextWrapping="Wrap"
                                                     MinWidth="100"/>
                                            <Button Content="🗑"
                                                    Margin="2"
                                                    Command="{Binding RelativeSource={RelativeSource AncestorType=Page}, Path=DataContext.DeleteAnswerCommand}"
                                                    CommandParameter="{Binding Id}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>

                            <Button Content="Добавить"
                                    HorizontalAlignment="Left"
                                    Margin="5,3"
                                    Command="{Binding RelativeSource={RelativeSource AncestorType=Page}, Path=DataContext.AddAnswerCommand}"
                                    CommandParameter="{Binding Id}"/>

                            <Button Content="Удалить вопрос"
                                    Command="{Binding RelativeSource={RelativeSource AncestorType=Page}, Path=DataContext.DeleteQuestionCommand}"
                                    CommandParameter="{Binding Id}"
                                    Margin="5"/>
                            </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>

        <UniformGrid Columns="4"
                     Grid.Row="2">
            <Button Content="Добавить вопрос"
                    Padding="5"
                    Margin="20,5"
                    Command="{Binding AddQuestionCommand}"/>
            <Button Content="Сохранить"
                    Padding="5"
                    Margin="20,5"
                    Command="{Binding SaveTestCommand}"/>
            <Button Content="Удалить"
                    Padding="5"
                    Margin="20,5"
                    Command="{Binding DeleteTestCommand}"/>
        </UniformGrid>
    </Grid>
</Page>
